// pages/userFour/userFour.js
import API from '../../utils/api'
import common from '../../utils/common'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    userIsimpower: true,
    myorders:[],
    myactives:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  toMyActivity (e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    wx.setStorageSync('myActivityId',id)
    wx.navigateTo({
      url:'/pages/memberActivityFiles/memberActivityFiles?id='+id
    })
  },
  onReady: function () {

  },
  getMemberCenterInfo () {
    API.memberCenter().then(res=>{
      console.log(res)
      if (res.code == 0) {
        var  myorders = res.data.myorders
        var myactives = res.data.myactives
        for (var k in myactives) {
          myactives[k].endtime = common.dateFormat(myactives[k].endtime,1)
        }
        for (var k in myorders) {
          myorders[k].endtime = common.dateFormat(myorders[k].endtime,1)
        }
        this.setData({
          myactives:myactives,
          myorders:myorders,
          userInfo:res.data.info
        })
      }
    })
  },
  toDetail (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url:'/pages/Eticket/Eticket?id='+id
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (wx.getStorageSync('editproduct_id')) {
      wx.removeStorageSync('setMoney')
      wx.removeStorageSync('pcate_id')
      wx.removeStorageSync('cate_id')
      wx.removeStorageSync('activityDetailPic')
      wx.removeStorageSync('product_id')
      wx.removeStorageSync('address')
      wx.removeStorageSync('latitude')
      wx.removeStorageSync('longitude')
      wx.removeStorageSync('pcate_name')
      wx.removeStorageSync('editproduct_id')
      wx.removeStorageSync('UpPic')
      wx.removeStorageSync('store_name')
      wx.removeStorageSync('pcate_name')
      wx.removeStorageSync('phone')
    }
    this.getMemberCenterInfo()
    var userInfo = wx.getStorageSync("userInfo")
    
    console.log(userInfo)
    if (userInfo) {
      var userInfoDeal = JSON.parse(wx.getStorageSync("userInfo"))
      this.setData({
        userInfo:userInfoDeal,
        userIsimpower: true
      })
    } else {
      wx.navigateTo({
        url: '/pages/login/login?form=2'
      })
      this.setData({
        userIsimpower: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})